package com.ncmmall.domain.business.goods.comment;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ncmmall.domain.business.goods.Goods;
import com.ncmmall.domain.security.user.WebUser;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Collections;
import java.util.List;

/**
 * @author linxs
 * @Description: 商品评论
 * @Date: 2019-07-17 17:01
 */
@Entity
@Table(name = "mall_goods_comment")
@Access(AccessType.FIELD)
@Getter
@Setter
public class GoodsComment {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    /**
     * 所属商品
     */
    @JsonBackReference
    @ManyToOne
    @JoinColumn(name = "goodsId")
    @NotFound(action = NotFoundAction.IGNORE)
    private Goods goods;

    /**
     * 所属商家
     */
    @JsonBackReference
    @OneToOne
    private WebUser merchant;

    /**
     * 所属会员
     */
    @OneToOne
    private WebUser member;

    /**
     * 星级
     * 1、2、3、4、5
     */
    private int starLever;

    /**
     * 评论内容
     */
    @Lob
    private String content;

    /**
     * 评论时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    private Timestamp createTime;


    /**
     * 评论图片集合
     */
    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "commentId")
    private List<GoodsCommentImage> images = Collections.emptyList();

    /**
     * 1、下架
     * 2、上架
     */
    private int status;

    /**
     * 0、用户商城端
     * 1、商家采购端
     */
    private int platformType;

}
